/*
 * OpenSCAD File with the code to draw a part of the quadcopter in 3D
 * Part Number: 02
 * Version: 0.01
 * Units: mm
 * Last Modification: Sun Jun 27 22:44:38 WEST 2010
 *
 * Copyright (C) 2010 Henrique Dias <henrique.ribeiro.dias@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

frominclude = 0;
p2_cylinderheight = 20;
p2_cylinderholeheight = 15;

module p2_subcomponent()
{
	// z cylinder hole
	translate(v = [0, 0, p2_cylinderholeheight/2+5]) {
		cylinder(h=p2_cylinderholeheight, r=2, center=true, $fn=60);
	}
	// x cylinder hole
	rotate(a=[0, 90, 0]) {
		cylinder(h=4+8*sqrt(2)+20+4+2, r=2, center=true, $fn=60);
	}
	rotate(a=[0,90,90+45]) {
		translate(v = [0, 10/sqrt(2), (15+1)/2+4/2+3+10/sqrt(2)]) {
			cylinder(h=15+1, r=2, center=true, $fn=60);
		}
	}
	rotate(a=[0,90,90-45]) {
		translate(v = [0, -(10/sqrt(2)), (15+1)/2+4/2+3+10/sqrt(2)]) {
			cylinder(h=15+1, r=2, center=true, $fn=60);
		}
	}

	translate(v = [10/sqrt(2)+(1.25*2-1.25*sqrt(2)), 4+1.25, 0]) {
		cylinder(h=3, r=1.25, center=true, $fn=60);
	}
	translate(v = [-(10/sqrt(2)+(1.25*2-1.25*sqrt(2))), 4+1.25, 0]) {
		cylinder(h=3, r=1.25, center=true, $fn=60);
	}

	rotate(a=[90,0,0]) {
		translate(v = [1.25+4, 1.25+4, 0]) {
			cylinder(h=2.5, r=1.25, center=true, $fn=60);
		}
		translate(v = [-(1.25+4), 1.25+4, 0]) {
			cylinder(h=2.5, r=1.25, center=true, $fn=60);
		}
	}

	// rings holes
	rotate(a=[90,0,90]) {
		// top
		translate(v = [3.25+2, 20-3.25, 0]) {
			cylinder(h=3, r=1.25, center=true, $fn=60);
		}
		// bottom
		translate(v = [3+2, 5, 0]) {
			cylinder(h=3, r=1, center=true, $fn=60);
		}
	}
}


module p2_addcomponent()
{
	// z cylinder
	rotate(a=[0,0,90]) {
		translate(v = [0, 0, p2_cylinderheight/2]) {
			cylinder(h=p2_cylinderheight, r=4, center=true, $fn=60);
		}
	}
	// x cylinder
	rotate(a=[0,90,0]) {
		cylinder(h=4+8*sqrt(2)+20+4, r=4, center=true, $fn=60);
		cube(size = [8, 2, 9], center=true);
	}
	rotate(a=[0,90,90+45]) {
		translate(v = [0, 10/sqrt(2), 20/2+10/sqrt(2)]) {
			cylinder(h=20, r=4, center=true, $fn=60);
		}
	}
	rotate(a=[0,90,90-45]) {
		translate(v = [0, -(10/sqrt(2)), 20/2+10/sqrt(2)]) {
			cylinder(h=20, r=4, center=true, $fn=60);
		}
	}

	rotate(a=[0, 0, 45]) {
		translate(v = [20/2+10/sqrt(2), -(10/sqrt(2)), 0]) {
			cube(size = [20, 2, 8], center=true);
		}
	}
	rotate(a=[0, 0, -45]) {
		translate(v = [-(20/2+10/sqrt(2)), -(10/sqrt(2)), 0]) {
			cube(size = [20, 2, 8], center=true);
		}
	}

	cube(size = [4+8*sqrt(2)+20+4, 2, 8], center=true);

	translate(v = [0, 0, 1.25+4]) {
		cube(size = [10.5, 2, 6.5], center=true);
	}
	translate(v = [0, 0, 2]) {
		cube(size = [17, 2, 6.5], center=true);
	}

	rotate(a=[90,0,0]) {
		translate(v = [1.25+4, 1.25+4, 0]) {
			cylinder(h=2, r=6.5/2, center=true, $fn=60);
		}
		translate(v = [-(1.25+4), 1.25+4, 0]) {
			cylinder(h=2, r=6.5/2, center=true, $fn=60);
		}
	}


	translate(v = [10/sqrt(2)+(1.25*2-1.25*sqrt(2)), 3+2, 0]) {
		cylinder(h=2, r=3, center=true, $fn=60);
	}
	translate(v = [-(10/sqrt(2)+(1.25*2-1.25*sqrt(2))), 3+2, 0]) {
		cylinder(h=2, r=3, center=true, $fn=60);
	}

	// support for the rings
	translate(v = [0, (4+1.25)/2, (p2_cylinderheight+8/2)/2-4]) {
		cube(size = [2, 4+1.25, p2_cylinderheight+8/2], center=true);
	}
	// rings
	rotate(a=[90,0,90]) {
		// top
		translate(v = [3.25+2, p2_cylinderheight-3.25, 0]) {
			cylinder(h=2, r=3.25, center=true, $fn=60);
		}
		// bottom
		translate(v = [3+2, 5, 0]) {
			cylinder(h=2, r=3, center=true, $fn=60);
		}
	}
	// central cylinder
	cylinder(h=8, r=4.5, center=true, $fn=60);
}

module part02()
{
	difference() {
		union() {
			p2_addcomponent();
		}
		p2_subcomponent();
	}
}

if(frominclude == 0) {
	part02();
}